package com.qifan.energy.util;

import android.app.Application;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.View;

import com.qifan.energy.global.MyApplication;

public class UIUtils {

    public static View getXmlView(int layoutId){
        return View.inflate(getContext(),layoutId,null);
    }

    public static int dp2px(int dp){
        float density = getContext().getResources().getDisplayMetrics().density;
        return (int)(dp*density + 0.5);
    }

    public static int px2dp(int px){
        float density = getContext().getResources().getDisplayMetrics().density;
        return (int)(px/density + 0.5);
    }

    public static int getDimensionPixelSize(int size){
        return getContext().getResources().getDimensionPixelSize(size);
    }

    public static Drawable getDrawable(int resId){
        return getContext().getResources().getDrawable(resId);
    }

    public static String getString(int resId){
        return getContext().getResources().getString(resId);
    }

    public static String[] getStringArr(int arrId){
        return getContext().getResources().getStringArray(arrId );
    }

    public static int getColor(int colorId){
        return getContext().getResources().getColor(colorId );
    }

    public static Context getContext(){
        return MyApplication.getContext();
    }

    public static Application getApplication(){
        return MyApplication.getApplication();
    }

    public static Handler getHandler(){
        return MyApplication.getHandler();
    }

    public static Handler getMainThreadid(){
        return MyApplication.getHandler();
    }
}
